#include "mergesort.h"

void MergeSort::sort(double *v, int p, int q){
	if (p<q-1){
		int m = (p+q)/2;
		sort(v, p, m);
		sort(v, m, q);

		int i = p, j = m, k = 0;
		double w[q - p];

		while (i < m && j < q){
			if (v[i] < v[j]) w[k++] = v[i++];
			else w[k++] = v[j++];
		}
		while (i<m) w[k++] = v[i++];
		while (j<q) w[k++] = v[j++];

		for (int l = p; l < q; l++){
			v[l] = w[l-p];
		}
	}
}
